<?php
namespace app\index\util;

use app\admin\code\BaseCode;
use think\Response as ResponseThink;
use think\Lang;

class Response
{
	static public $param;

    public function __construct(){}

    // 输出html
    static public function view($template = '', $vars = [], $replace = [], $code = 200){
        return ResponseThink::create($template, 'view', $code)->replace($replace)->assign($vars)->send();
    }

    // 跳转
    static public function redirect($url = [], $params = [], $code = 302, $with = []){
        return ResponseThink::create($url, 'redirect', $code)->params($params)->with($with)->send();
    }

    static public function json($code = BaseCode::SUCCESS,$msg = '操作成功',$data=''){
        if($data === ''){
            $data = (object)[];
        }
    	self::$param['code'] = $code;
    	self::$param['msg']  = $msg;
    	self::$param['data'] = $data;
    	self::sendJson(self::$param);
    }

    static public function sendJson($data,$code=200,$header=[],$options=[]){
    	ResponseThink::create($data, 'json', $code, $header, $options)->send();
    	exit();
    }
}
